$(function(){
    $.get("/system/site/revenue",
        function(data){
            var cash_pay = data.cash_pay||0;
            var unionpay = data.unionpay||0;
            var myChart1 = echarts.init(document.getElementById('con1'));
            var option1 = {

                tooltip : {
                    trigger: 'item',
                    formatter: "{d}%"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                },
                textStyle : {
                    color:'#6f6f6f',
                },
                series : [
                    {
                        name: '今日营收',
                        type: 'pie',
                        radius : ['35%', '55%'],
                        center: ['50%', '50%'],
                        label: {
                            normal: {
                                position: 'outside'
                            }
                        },
                        data:[
                            {value:cash_pay, name:'现金收入\n'+'(￥'+cash_pay+')'},
                            {value:unionpay, name:'刷卡收入\n'+'(￥'+unionpay+')'},

                        ],

                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                    }
                ],
                color: [
                    '#ffb230', '#fe7b9d', '#e8477d', '#fa6382', '#e8477d',
                    '#fe9494', '#ba55d3', '#cd5c5c', '#ffa500', '#40e0d0',
                    '#1e90ff', '#ff6347', '#7b68ee', '#00fa9a', '#ffd700',
                    '#6b8e23', '#ff00ff', '#3cb371', '#b8860b', '#30e0e0'
                ]
            };
            myChart1.setOption(option1);

            var myChart2 = echarts.init(document.getElementById('con2'));
            var option2 = {
                title: {
                },

                legend: {
                },
                xAxis: {
                    data: ["营业收入","消耗金额","扣赠送金额","卡扣金额"],
                    splitLine: {
                        show: false
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#e5e5e5'
                        }
                    },
                    axisTick: {
                        show:false
                    },
                },
                yAxis: {
                    type: 'value',
                    min: 0,
                    /*max: 100,
                     interval: 25,*/
                    axisLine: {
                        show:false,
                        lineStyle: {
                            color: '#e5e5e5'
                        }
                    },
                    axisTick: {
                        show:false
                    },
                    splitLine: {
                        lineStyle:{
                            type:'dashed'
                        }
                    },
                },
                series: [{
                    name: '',
                    type: 'bar',
                    barMinHeight:5,
                    label: {
                        normal: {
                            formatter: '￥{c}',
                            show: true,
                            position: 'top',
                            textStyle:{
                                color:'#6f6f6f'
                            }
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 0.8, [{
                                offset: 0,
                                color: '#f78ca8'
                            }, {
                                offset: 1,
                                color: '#fce5a2'
                            }])
                        }
                    },
                    data: [
                        {   value:data.consume_amount||0,
                            name: '营业收入(20%)',
                        },
                        {   value:data.consume_amount_extends||0,
                            name: '消耗金额(20%)',
                        },
                        {   value:data.give_pay||0,
                            name: '扣赠送金额(20%)',

                        },
                        {   value:data.balance_pay||0,
                            name: '卡扣金额(20%)',
                        },
                    ]
                }]

            }
            myChart2.setOption(option2);
        }, "json");


    $.get('/system/site/salemap',function(data){

        var monthArr =[],
            val = [];
        $.each(data,function(i,o){
            monthArr.push(i);
            val.push(o);
        });
        function tranN(x){
            if(x==null){
                return 0;
            } else {
                return x;
            }
        }
        var val2 = val.map(tranN);
        var myChart3 = echarts.init(document.getElementById('monthCon'));

        // 指定图表的配置项和数据
        var oridata = val2;
        var data0 = [];
        for (var i = 0, l = oridata.length; i < l; i++) {
            total = oridata[i];
            data0.push(Math.round(total * 1));
        }



        var option3 = {

            legend: {
                data:['1'],
                show:false
            },
            grid:{
                width:'94%',
                left:30,
                containLabel:true,
            },
            calculable : true,
            xAxis : [
                {
                    name:'时间',
                    type : 'category',
                    splitLine: {
                        show: false
                    },
                    nameTextStyle: {
                        color:'#878DA1' ,
                        fontSize:'14px',
                    },
                    axisLine: {
                        show:false,
                        lineStyle: {
                            color: '#e5e5e5',
                        }
                    },
                    axisTick: {
                        show:false
                    },
                    data : monthArr
                }
            ],
            yAxis : [
                {
                    name:'营业收入',
                    type : 'value',
                    min: 0,
                    /*                max: 2500,
                     interval: 250,*/
                    axisLine: {
                        show:false,
                        lineStyle: {
                            color: '#e5e5e5'
                        }
                    },
                    axisTick: {
                        show:false
                    },
                    splitLine: {
                        lineStyle:{
                            type:'dashed'
                        }
                    },
                    nameTextStyle: {
                        color:'#878DA1' ,
                        fontSize:'14px',
                    },
                    nameGap:'25',
                    splitArea : {show : false}
                }
            ],
            series : [

                {

                    name:'1',
                    type:'bar',
                    barMinHeight:5,
                    barWidth:35,
                    stack: '广告',
                    barCategoryGap:'10%',
                    label: {
                        normal: {
                            show: true,
                            formatter: '{c}',
                            position: 'top',
                            textStyle:{
                                color:'#6f6f6f',
                            }
                        }
                    },
                    itemStyle: {
                        normal: {
                            show:false,
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 0.8, [{
                                offset: 0,
                                color: '#f78ca8'
                            }, {
                                offset: 1,
                                color: '#fce5a2'
                            }])
                        }
                    },
                    data:data0,
                },
            ]

        };

        myChart3.setOption(option3);

    },'json')
})

// 页面动效
$(function(){
    var $tips = $('.home-tips')
    $tips.find('.content').hover(function(){
        $(this).addClass('ct-hover');
    },function(){
        $(this).removeClass('ct-hover');
    })

})